<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->

      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        :selection.sync="selection"
      >
        <!-- 表头工具栏 -->

        <template v-slot:action="{ row }">
          <el-link
            type="success"
            :underline="false"
            icon="el-icon-_user-group"
            @click="openOperationUser(row)"
          >
            运营用户
          </el-link>
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-_user-group"
            @click="agentCk(row)"
          >
            代理用户
          </el-link>
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 编辑弹窗 -->
    <ele-modal
      width="80%"
      :close-on-click-modal="false"
      custom-class="ele-dialog-form"
      :title="userName + '运营用户'"
      :visible.sync="operationUser"
    >
      <operationUser :data="current" :uid="id" @done="reload" />
    </ele-modal>

     <ele-modal
      width="80%"
      :close-on-click-modal="false"
      custom-class="ele-dialog-form"
      :title="userName + '代理用户'"
      :visible.sync="agentBol"
    >
       <agent :visible.sync="agentBol" :data="current" :uid="id" @done="reload"/>
    </ele-modal>

  
  </div>
</template>

<script>
import { site } from '@/api/account/list';
import Sortable from 'sortablejs';
import OperationUser from './components/operationUser';
import Agent from './components/agent';
export default {
  name: 'Composite',
  components: {
    OperationUser,
    Agent
  },
  data() {
    return {
      host: window.location.protocol + '//' + location.host,
      // 表格列配置
      columns: [
        {
          columnKey: 'selection',
          type: 'selection',
          width: 45,
          align: 'center',
          fixed: 'left'
        },

        {
          prop: 'site_url',
          label: '站点域名',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110
        },

        {
          columnKey: 'action',
          label: '操作',
          width: 350,
          align: 'center',
          resizable: false,
          slot: 'action',
          hideInSetting: true,
          showOverflowTooltip: true
        }
      ],
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      // 是否显示分配回收员
      showCollector: false,
      operationUser: false,
      agentBol: false,
      //弹框名称
      id: 0
    };
  },
  methods: {
    copy_url(content) {
      if (window.clipboardData) {
        window.clipboardData.setData('text', content);
      } else {
        (function (content) {
          //oncopy 事件在用户拷贝元素上的内容时触发。
          document.oncopy = function (e) {
            e.clipboardData.setData('text', content);
            e.preventDefault(); //取消事件的默认动作
            document.oncopy = null;
          };
        })(content);
        document.execCommand('Copy');
      }
      this.$message.success('复制成功！');
    },
    /* 表格数据源 */
    datasource({ page, limit, where, order }) {
      return site({ ...where, ...order, page, limit });
    },
    /* 刷新表格 */
    reload(where) {
      this.$refs.table.reload({ page: 1, where: where });
    },
    openOperationUser(row) {
      this.id = row.id;
      this.current = row;
      this.operationUser = true;
      this.userName = row.site_url;
    },
    agentCk(row) {
      this.id = row.id;
      this.current = row;
      this.agentBol = true;
      this.userName = row.site_url;
    },
    /* 打开编辑弹窗 */
    openEdit(row) {
      this.current = row;
      this.showEdit = true;
    },
    /* 删除 */
    remove(row) {
      const loading = this.$loading({ lock: true });
      remove(row.id)
        .then((msg) => {
          loading.close();
          this.$message.success(msg);
          this.reload();
        })
        .catch((e) => {
          loading.close();
          this.$message.error(e.message);
        });
    },

    /* 一键默认 */
    doDefault() {
      this.$confirm(
        '请谨慎使用该功能，一旦使用则会变成系统默认内容。确定一键默认？',
        '提示',
        {
          type: 'warning'
        }
      )
        .then(() => {
          const loading = this.$loading({ lock: true });
          doDefault()
            .then((msg) => {
              loading.close();
              this.$message.success(msg);
              this.reload();
            })
            .catch((e) => {
              loading.close();
              this.$message.error(e.message);
            });
        })
        .catch(() => {});
    },

    /* 批量删除 */
    removeBatch() {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据');
        return;
      }
      this.$confirm('确定要删除选中的数据吗?', '提示', {
        type: 'warning'
      })
        .then(() => {
          const loading = this.$loading({ lock: true });
          remove(this.selection.map((d) => d.id))
            .then((msg) => {
              loading.close();
              this.$message.success(msg);
              this.reload();
            })
            .catch((e) => {
              loading.close();
              this.$message.error(e.message);
            });
        })
        .catch(() => {});
    },

    /* 更改状态 */
    editStatus(row) {
      const loading = this.$loading({ lock: true });
      modify({ id: row.id, field: 'is_display', value: row.is_display })
        .then((msg) => {
          loading.close();
          this.$message.success(msg);
        })
        .catch((e) => {
          loading.close();
          row.status = !row.status ? 1 : 0;
          this.$message.error(e.message);
        });
    }
  },
  mounted() {
    //this.columnDrop()
  }
};
</script>

<style>
.drag {
  background: #000 !important;
  background-image: linear-gradient(#333, #999) !important;
}
</style>
